package com.aaa.service.system.impl;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.system.Dept;
import com.aaa.dao.system.DeptDao;
import com.aaa.service.system.DeptService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 部门表(Dept)表服务实现类
 *
 * @author makejava
 * @since 2022-08-30 20:06:58
 */
@Service("deptService")
public class DeptServiceImpl implements DeptService {
    @Resource
    private DeptDao deptDao;


    /**
     * @param pageSortEntity
     * @param dept
     * @return
     * @create by: 张恒
     * @description: 查询
     * @create time: 2022/9/2 21:17
     */
    @Override
    public Page queryDeptPage(PageSortEntity pageSortEntity, Dept dept) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<Map<String, Object>> mapList = deptDao.queryDeptPage(dept);
        Page page = (Page) mapList;
        return page;
    }

    /**
     * @param
     * @return
     * @create by: 张恒
     * @description: 查询所有，不带分页，实体类
     * @create time: 2022/9/3 9:30
     */
    @Override
    public List<Dept> queryAllDept() {
        return deptDao.queryAllDept();
    }

    /**
     * @param dept
     * @return
     * @create by: 张恒
     * @description: 添加
     * @create time: 2022/9/2 21:17
     */
    @Override
    @InsertAnn
    public boolean insertDept(Dept dept) {
        return deptDao.insertDept(dept);
    }

    /**
     * @param dept
     * @return
     * @create by: 张恒
     * @description: 修改
     * @create time: 2022/9/2 21:18
     */
    @Override
    @UpdateAnn
    public boolean updateDept(Dept dept) {
        return deptDao.updateDept(dept);
    }

    /**
     * @param id
     * @return
     * @create by: 张恒
     * @description: 删除
     * @create time: 2022/9/2 21:18
     */
    @Override
    public boolean deleteDeptById(Integer[] id) {
        return deptDao.deleteDeptById(id);
    }


    /**
     * 联合userinfo表查部门中的人数
     */
    @Override
    public Integer selectDeptUser(Integer deptId) {
        return deptDao.selectDeptUser(deptId);
    }


    /**
     * @param dept
     * @return
     * @create by: 张恒
     * @description: 唯一校验
     * @create time: 2022/9/3 17:00
     */
    @Override
    public boolean repetitionName(Dept dept) {
        Integer integer = deptDao.repetitionName(dept);
        if (integer > 0) {
            return false;
        }
        return true;
    }
}
